<template>
  <div class="containerHall">
    <el-dialog
      :title="dialogConfig.name"
      :visible.sync="dialogVisible"
      @close="dialogVisible = false"
      append-to-body
    >
      <el-form ref="formRef">
        <el-form-item label="uid" :label-width="'100px'" prop="name">
          <el-input
            v-model="formData.uid"
            autocomplete="off"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item label="备注" :label-width="'100px'" prop="link">
          <el-input v-model="remark" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="时间" :label-width="'100px'" prop="seqencing">
          <el-date-picker
            v-model="endTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="timestamp"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { deepClone } from '@/utils'
import { userNoBennedApi, userBennedApi } from '@api/whisper'
export default {
  components: {},
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    value: {
      type: Object
    },
    request: {
      type: Object
    },
    dialogConfig: {
      type: Object
    }
  },
  data() {
    return {
      posting: false,
      formData: this.setup(this.value),
      rules: {},
      endTime: '',
      remark: ''
    }
  },
  created() {},
  mounted() {},
  methods: {
    setup() {
      if (this.value) {
        const clone = deepClone(this.value)
        console.log('clonecloneclone', clone)
        return clone
      }
    },
    handleConfirm() {
      this.posting = true
      let func = null
      if (this.dialogConfig.name == '封禁') {
        func = userBennedApi
      } else {
        func = userNoBennedApi
      }
      const clone = {
        endTime: this.endTime,
        remark: this.remark,
        uid: this.formData.uid
      }
      func(clone)
        .then(res => {
          this.dialogVisible = false
          this.$emit('success') // 刷新
        })
        .catch(err => {
          this.$message('error')
        })
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.formData = this.setup()
      }
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.containerHall {
}
</style>
